/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2010
 */

package com.hibernate.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "MATERIAL_SITE_PLAY")
public class MaterialSitePlay extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "MaterialSitePlay";
	public static final String ALIAS_ID = "id";
	public static final String ALIAS_MATERIAL_ID = "materialId";
	public static final String ALIAS_SITE_ID = "siteId";
	public static final String ALIAS_PROVINCE_ID = "provinceId";
	public static final String ALIAS_PROPERTY_VALUE_ID = "propertyValueId";
	public static final String ALIAS_CLICK_URL = "clickUrl";
	
	//date formats
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	
	private Long id;
	@NotNull 
	private Long materialId;
	@NotNull 
	private Long siteId;

	@NotBlank @Length(max=1000)
	private java.lang.String clickUrl;
	
	/**
	 * 1开启，2停用,3删除
	 */
	private String status;
	//columns END


	public MaterialSitePlay(){
	}

	public MaterialSitePlay(
		Long id
	){
		this.id = id;
	}

	

	public void setId(Long value) {
		this.id = value;
	}
	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "ID", unique = true,  insertable = true, updatable = true, length = 20)
	public Long getId() {
		return this.id;
	}
	
	@Column(name = "MATERIAL_ID", unique = false,  insertable = true, updatable = true, length = 20)
	public Long getMaterialId() {
		return this.materialId;
	}
	
	public void setMaterialId(Long value) {
		this.materialId = value;
	}
	
	@Column(name = "SITE_ID", unique = false,  insertable = true, updatable = true, length = 20)
	public Long getSiteId() {
		return this.siteId;
	}
	
	public void setSiteId(Long value) {
		this.siteId = value;
	}
	
	@Column(name = "STATUS")
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}
	
	@Column(name = "CLICK_URL", unique = false,  insertable = true, updatable = true, length = 1000)
	public java.lang.String getClickUrl() {
		return this.clickUrl;
	}
	
	public void setClickUrl(java.lang.String value) {
		this.clickUrl = value;
	}
	
	private Material material;
	public void setMaterial(Material material){
		this.material = material;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "MATERIAL_ID", insertable = false, updatable = false) 
	})
	public Material getMaterial() {
		return material;
	}
	
	private AdSite adSite;
	public void setAdSite(AdSite adSite){
		this.adSite = adSite;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "SITE_ID", insertable = false, updatable = false) 
	})
	public AdSite getAdSite() {
		return adSite;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Id",getId())
			.append("MaterialId",getMaterialId())
			.append("SiteId",getSiteId())
			.append("ClickUrl",getClickUrl())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof MaterialSitePlay == false) return false;
		if(this == obj) return true;
		MaterialSitePlay other = (MaterialSitePlay)obj;
		return new EqualsBuilder()
			.append(getId(),other.getId())
			.isEquals();
	}
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "物料与广告位关联";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return getId();
	}
	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return "MATERIAL_SITE_PLAY" + getId();
	}
}

